package de.wittekind.bundesjugendspiele.server.mysqlTools;

import java.io.IOException;
import java.sql.SQLException;

import de.wittekind.bundesjugendspiele.server.db.DBServer;
import de.wittekind.bundesjugendspiele.server.rpcTools.RPCHelper;

public class MySQLServer implements DBServer{

	private RPCHelper helper;
	private String host, user, password, database;

	public MySQLServer(RPCHelper helper, String host, String user,
			String password, String database) {
		this(host, user, password, database);
		this.helper = helper;
	}

	public MySQLServer(String host, String user, String password,
			String database) {
		this.host = host;
		this.user = user;
		this.password = password;
		this.database = database;
	}

	public void start() {
		try {
			MySQLConnectionManager.init("jdbc:mysql://" + host + "/" + database
					+ "?user=" + user + "&password=" + password);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		if (helper != null) {
			try {
				helper.exportNewLoader();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public void stop() {
		MySQLConnectionManager.shutdown();
		MySQLConnectionManager.close();
	}

}
